package com.example.zhu95.mytimber.fragments;

import android.os.Bundle;
import android.os.Environment;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.zhu95.mytimber.R;
import com.example.zhu95.mytimber.adapters.FolderItemAdapter;
import com.example.zhu95.mytimber.ui.FolderSectionTitleIndicator;

import xyz.danoz.recyclerviewfastscroller.vertical.VerticalRecyclerViewFastScroller;


public class FoldersFragment extends BaseFragment {

    RecyclerView recyclerViewFolder = null;
    FolderItemAdapter folderItemAdapter = null;
    VerticalRecyclerViewFastScroller scroller;
    FolderSectionTitleIndicator indicator;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        super.onCreateView(inflater, container, savedInstanceState);

        View view = inflater.inflate(R.layout.fragment_folders, container, false);
        //AppCompatActivity rootActivity = (AppCompatActivity) getActivity();

        Toolbar toolbar = view.findViewById(R.id.toolbar);
        recyclerViewFolder = view.findViewById(R.id.recycler_view_folder);
        scroller = view.findViewById(R.id.scroller_folder);
        indicator = view.findViewById(R.id.indicator_folder);

        LinearLayoutManager layoutManager = new LinearLayoutManager(container.getContext(), LinearLayoutManager.VERTICAL, false);
        recyclerViewFolder.setLayoutManager(layoutManager);
        if (folderItemAdapter == null) {
            folderItemAdapter = new FolderItemAdapter(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC));
        }
        recyclerViewFolder.setAdapter(folderItemAdapter);
        scroller.setRecyclerView(recyclerViewFolder);
        recyclerViewFolder.setOnScrollListener(scroller.getOnScrollListener());
        scroller.setSectionIndicator(indicator);

        rootActivity.setSupportActionBar(toolbar);
        toolbar.setTitle(R.string.Folders);

        DrawerLayout drawer = (DrawerLayout) rootActivity.findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                rootActivity, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();

        setHasOptionsMenu(true);
        return view;
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        // inflater.inflate(R.menu.fragment_playlist_popup, menu);
        super.onCreateOptionsMenu(menu, inflater);
        menu.findItem(R.id.action_order_by).setVisible(false);
        //inflater.inflate(R.menu.fragment_folders_popup, menu);
    }


}
